package com.demo.spring.memory2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;

@Configuration
public class CommonConfig {

	@Autowired
	private OpenAiChatModel model;
	
	// 构建会话记忆体
	@Bean
	public ChatMemoryProvider chatMemoryProvider() {
		ChatMemoryProvider chatMemoryProvider = new ChatMemoryProvider() {

			public ChatMemory get(Object memoryId) {
				MessageWindowChatMemory memory = MessageWindowChatMemory.builder()
						.id(memoryId)
						.maxMessages(20)
						.build();
				return memory;
			}
			
		};
		return chatMemoryProvider;
	}
	
}
